package driver;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * User: Igor.Sirokhman
 * Date: 11/6/13
 * Time: 8:05 PM
 * To change this template use File | Settings | File Templates.
 */
public class moscow
{
    public WebDriver driver;
     @BeforeSuite
    public void start ()
    {
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
    }


    @Test
    public void test () throws InterruptedException
    {

        driver.get("http://vmdaily.ru/");
        driver.findElement(By.xpath("html/body/div/section[2]/div/div/div[1]/div[1]/article/h3/a")).click();
        driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[1]/button")).click();
        driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[2]/form/div[3]/div")).sendKeys("Comment for adding");
        driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[2]/form/div[4]/input[4]")).click();
        String comment = driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[2]/form/div[1]/span[1]")).getText();
        String exit;
        if (comment.equals("Комментарий успешно отправлен"))
        {
            exit = "Комментарий успешно отправлен";
            System.out.println(exit);
        }
        else
        {
            exit = "Комментарий не отправлен";
            System.out.println(exit);
        }
        TimeUnit.SECONDS.sleep(3);
        driver.get("http://vmdaily.ru/");
        TimeUnit.SECONDS.sleep(3);
        driver.findElement(By.xpath(".//*[@id='user-info']/form/div[1]/div[2]/div[1]/input[1]")).sendKeys("moscow.city");
        driver.findElement(By.xpath(".//*[@id='user-info']/form/div[1]/div[2]/div[2]/input")).sendKeys("123123",Keys.ENTER);
        driver.findElement(By.xpath("html/body/div/section[2]/div/div/div[1]/div[1]/article/h3/a")).click();
        driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[1]/button")).click();
        driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[2]/form/div[3]/div")).sendKeys("Comment for adding");
        driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[2]/form/div[4]/input[4]")).click();
        comment = driver.findElement(By.xpath("html/body/div/section/section/article/div[9]/div[2]/form/div[1]/span[1]")).getText();
        if (comment.equals("Комментарий успешно отправлен"))
        {
            exit = "Комментарий успешно отправлен";
            System.out.println(exit);
        }
        else
        {
            exit = "Комментарий не отправлен";
            System.out.println(exit);
        }

        TimeUnit.SECONDS.sleep(3);
        driver.quit();
    }


    @AfterSuite
    public void Clean ()
    {
        if  (driver!=null)
            driver.quit();
    }
}










